﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Emoney.UserTraining.BLL;
using Emoney.UserTraining.Model;

namespace Emoney.UserTraining.Admin.aspx
{
    public partial class NetworkMeetingAdd : System.Web.UI.Page
    {
        Traning_NetworkMeetingBLL bll = new Traning_NetworkMeetingBLL();

        public string id = "";
        public string UpType = "";
        Traning_NetworkMeeting che = new Traning_NetworkMeeting();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
                string keyvalue = getCookie("webadmin", "adminname");
                if (keyvalue != null)
                {
                    if (keyvalue == "admin")
                    {
                        if (Request.QueryString["id"] != null && Request.QueryString["id"].ToString() != "")
                        {
                            id = Request.QueryString["id"].ToString();
                            ShowInfoById(Request.QueryString["id"].ToString());
                            button2.Value = " 修 改 ";

                            if (!string.IsNullOrEmpty(Request.QueryString["type"]))
                            {
                                UpType = Request.QueryString["type"].ToString();
                            }
                        }
                        else
                        {
                            class_date.Value = System.DateTime.Now.ToString("yyyy-MM-dd");
                            starttime_hour.Value = System.DateTime.Now.ToString("HH");
                            starttime_minute.Value = System.DateTime.Now.ToString("mm");

                            this.txtStartTime.Value = System.DateTime.Now.ToString("yyyy-MM-dd");
                            this.txtendTime.Value = System.DateTime.Now.AddMonths(1).ToString("yyyy-MM-dd");
                        }
                    }
                    else
                    {
                        ClientScript.RegisterStartupScript(GetType(), "aa", "alert('您没有权限操作此页面！');document.location.href='index'", true);
                        return;
                    }
                }
                else
                {
                    ClientScript.RegisterStartupScript(GetType(), "aa", "alert('登录超时或您还没有登录，请登录！');document.location.href='index';", true);
                }
            }
        }

        /// <summary>
        /// 加载数据
        /// </summary>
        public void LoadData()
        {
            Traning_LecturerBLL tbll = new Traning_LecturerBLL();
            List<Traning_Lecturer> tlist = new List<Traning_Lecturer>();
            tlist = tbll.GetList();
            ddl_txtteachar.DataSource = tlist;
            ddl_txtteachar.DataBind();
            ddl_txtteachar.Items.Insert(0, "请选择讲师");

            Traning_MeetingTypeBLL mbll = new Traning_MeetingTypeBLL();
            List<Traning_MeetingType> mlist = new List<Traning_MeetingType>();
            mlist = mbll.GetAllList();
            uddl_meeting_type.DataSource = mlist;
            uddl_meeting_type.DataTextField = "meetingType";
            uddl_meeting_type.DataValueField = "id";
            uddl_meeting_type.DataBind();
            uddl_meeting_type._TextBox.Text = "";
            //ddl_meeting_type._DropDownList.DataSource = mlist;
            //ddl_meeting_type._DropDownList.DataTextField = "meetingType";
            //ddl_meeting_type._DropDownList.DataValueField = "id";
            //ddl_meeting_type._DropDownList.DataBind();
        }

        public string getCookie(string cookieName, string keyguid)
        {
            if (HttpContext.Current.Request.Cookies[cookieName] != null)
            {
                //读取Cookie 键值
                return HttpContext.Current.Request.Cookies[cookieName][keyguid].ToString();
            }
            return "";
        }

        public void ShowInfoById(string id)
        {
            Traning_NetworkMeeting list = bll.GetModel(Convert.ToInt32(id));
            if (list != null)
            {
                che = list;
                mtg_ID.Value = che.mtg_id;
                mtg_name.Value = che.mtg_name;
                mtg_conent.Value = che.mtg_conent;
                if (!string.IsNullOrEmpty(che.meeting_type))
                {
                    uddl_meeting_type._TextBox.Text = che.meeting_type;
                    if (uddl_meeting_type.Items.FindByText(che.meeting_type) != null)
                        uddl_meeting_type.Items.FindByText(che.meeting_type).Selected = true;
                }
                user_type.Value = che.user_type;

                if (!string.IsNullOrEmpty(che.txtteachar))
                {
                    txtteachar.Value = che.txtteachar;
                    if (ddl_txtteachar.Items.FindByText(che.txtteachar) != null)
                    {
                        ddl_txtteachar.Items.FindByText(che.txtteachar).Selected = true;
                    }
                    else
                    {
                        ddl_txtteachar.Items.Add(che.txtteachar);
                        ddl_txtteachar.Items.FindByText(che.txtteachar).Selected = true;
                    }
                }
                if (!string.IsNullOrEmpty(che.lecturerImage))
                {
                    lecturerImages.ImageUrl = che.lecturerImage;
                    lecturerImage.Value = che.lecturerImage;
                }
                txtreateachar.Value = che.txtreateachar;
                host_key.Value = che.host_key;
                mtg_password.Value = che.mtg_password;
                txt_phone.Value = che.txt_phone;

                txt_satisfaction.Value = che.satisfaction;

                mtg_ID1.Value = che.mtg_id;
                mtg_password1.Value = che.mtg_password;
                txtGensee_URL.Value = che.Gensee_URL;

                if (che.isRecommend == "1")
                {
                    isRecommend0.Checked = false;
                    isRecommend1.Checked = true;
                }
                else
                {
                    isRecommend0.Checked = true;
                    isRecommend1.Checked = false;
                }

                if (che.mtg_view == "1")
                {
                    mtg_view0.Checked = false;
                    mtg_view1.Checked = true;
                }
                else
                {
                    mtg_view0.Checked = true;
                    mtg_view1.Checked = false;
                }

                if (che.use_num != null && che.use_num != "")
                {
                    if (Convert.ToInt32(che.use_num) > 0)
                    {
                        person_flag.Checked = true;
                        use_num.Value = che.use_num;
                    }
                    else
                    {
                        use_num.Disabled = false;
                        person_flag.Checked = false;
                    }
                }
                else
                {
                    use_num.Disabled = false;
                    person_flag.Checked = false;
                }

                host_id.Value = che.host_id;
                pres_id.Value = che.pres_id;

                if (che.pri_name != null)
                {
                    if (che.pri_name.Contains("1"))
                        pri11.Checked = true;
                    else
                        pri11.Checked = false;
                    if (che.pri_name.Contains("2"))
                        pri12.Checked = true;
                    else
                        pri12.Checked = false;
                    if (che.pri_name.Contains("3"))
                        pri13.Checked = true;
                    else
                        pri13.Checked = false;
                    if (che.pri_name.Contains("4"))
                        pri14.Checked = true;
                    else
                        pri14.Checked = false;
                }

                if (che.radDisplayType == "1")
                {
                    radDisplayType1.Checked = true;
                    radDisplayType2.Checked = false;
                }
                else
                {
                    radDisplayType1.Checked = false;
                    radDisplayType2.Checked = true;
                }

                ddlarea.Value = che.ddlarea;
                che.chblist_pro = "," + che.chblist_pro + ",";

                if (che.chblist_pro.Contains(",100,"))
                    chblist_pro_0.Checked = true;
                if (che.chblist_pro.Contains(",101,"))
                    chblist_pro_1.Checked = true;
                if (che.chblist_pro.Contains(",109,"))
                    chblist_pro_2.Checked = true;
                if (che.chblist_pro.Contains(",121,"))
                    chblist_pro_4.Checked = true;
                if (che.chblist_pro.Contains(",131,"))
                    chblist_pro_5.Checked = true;
                if (che.chblist_pro.Contains(",151,"))
                    chblist_pro_7.Checked = true;

                if (che.chblist_pro.Contains(",152,"))
                    chblist_pro_8.Checked = true;
                if (che.chblist_pro.Contains(",158,"))
                    chblist_pro_9.Checked = true;
                if (che.chblist_pro.Contains(",202,"))
                    chblist_pro_10.Checked = true;
                if (che.chblist_pro.Contains(",230,"))
                    chblist_pro_11.Checked = true;

                if (che.chblist_pro.Contains(",212,"))
                    chblist_pro_12.Checked = true;
                if (che.chblist_pro.Contains(",220,"))
                    chblist_pro_13.Checked = true;
                if (che.chblist_pro.Contains(",700,"))
                    chblist_pro_14.Checked = true;
                if (che.chblist_pro.Contains(",710,"))
                    chblist_pro_15.Checked = true;
                if (che.chblist_pro.Contains(",800,"))
                    chblist_pro_16.Checked = true;
                if (che.chblist_pro.Contains(",900,"))
                    chblist_pro_17.Checked = true;

                if (che.chblist_pro.Contains(",102,"))
                    chblist_pro_18.Checked = true;

                if (che.chblist_pro.Contains(",1131,"))
                    chblist_pro_19.Checked = true;

                if (che.chblist_pro.Contains(",1132,"))
                    chblist_pro_20.Checked = true;

                if (che.chblist_pro.Contains(",1133,"))
                    chblist_pro_21.Checked = true;

                if (che.chblist_pro.Contains(",1134,"))
                    chblist_pro_22.Checked = true;
                if (che.chblist_pro.Contains(",1411,"))
                    chblist_pro_23.Checked = true;
                if (che.chblist_pro.Contains(",1412,"))
                    chblist_pro_24.Checked = true;

                if (che.chblist_pro.Contains(",157,"))
                    chblist_pro_25.Checked = true;
                if (che.chblist_pro.Contains(",1141,"))
                    chblist_pro_26.Checked = true;
                if (che.chblist_pro.Contains(",202100000,"))
                    chblist_pro_27.Checked = true;
                if (che.chblist_pro.Contains(",211,"))
                    chblist_pro_28.Checked = true;
                if (che.chblist_pro.Contains(",116000000,"))
                    chblist_pro_29.Checked = true;
                if (che.chblist_pro.Contains(",zt_100,"))
                    chblist_pro_30.Checked = true;
                if (che.chblist_pro.Contains(",zt_131,"))
                    chblist_pro_31.Checked = true;
                if (che.chblist_pro.Contains(",zt_202,"))
                    chblist_pro_32.Checked = true;
                if (che.chblist_pro.Contains(",zt_202100000,"))
                    chblist_pro_33.Checked = true;
                if (che.chblist_pro.Contains(",zt_101,"))
                    chblist_pro_34.Checked = true;
                if (che.chblist_pro.Contains(",zt_152,"))
                    chblist_pro_35.Checked = true;
                if (che.chblist_pro.Contains(",zt_121,"))
                    chblist_pro_36.Checked = true;


                click1.Disabled = true;
                click2.Disabled = true;
                if (che.click_num != "0")
                {
                    //开始时间
                    selstarthour.Value = che.class_date.ToString("HH");//时
                    selstartmm.Value = che.class_date.ToString("mm");//分
                    //持续时间

                    selchixuhour.Value = Convert.ToInt32(Convert.ToInt32(che.Duration_date) / 60).ToString("00");//时
                    selchixumm.Value = Convert.ToInt32(Convert.ToInt32(che.Duration_date) % 60).ToString("00");//分
                    this.ClientScript.RegisterStartupScript(GetType(), "", "<script>f_clicks(2);</script>");
                    click1.Checked = false;
                    click2.Checked = true;
                }
                else
                {
                    this.ClientScript.RegisterStartupScript(GetType(), "", "<script>f_clicks(1);</script>");
                    click1.Checked = true;
                    click2.Checked = false;
                }

                if (che.startDate != null && che.startDate != DateTime.MinValue)
                {
                    txtStartTime.Value = che.startDate.ToString("yyyy-MM-dd");
                }
                if (che.endDate != null && che.endDate != DateTime.MinValue)
                {
                    txtendTime.Value = che.endDate.ToString("yyyy-MM-dd");
                }
                //radxunhuan1.Disabled = true;
                //radxunhuan2.Disabled = true;
                //period1.Disabled = true;
                //period2.Disabled = true;
                //period3.Disabled = true;
                //period4.Disabled = true;
                //period5.Disabled = true;
                //period6.Disabled = true;
                //period7.Disabled = true;
                //txtStartTime.Disabled = true;
                //txtendTime.Disabled = true;
                //selstarthour.Disabled = true;
                //selstartmm.Disabled = true;
                //selchixuhour.Disabled = true;
                //selchixumm.Disabled = true;
                //before_hour.Disabled = true;
                //before_time.Disabled = true;

                ////单次
                //starttime_hour.Disabled = true;
                //class_date.Disabled = true;
                //starttime_minute.Disabled = true;
                //Duration_hour.Disabled = true;
                //Duration_minute.Disabled = true;

                if (che.period != "0")
                {
                    this.ClientScript.RegisterStartupScript(GetType(), "msg", "<script>f_xuanhuan(2);</script>");
                    radxunhuan1.Checked = false;
                    radxunhuan2.Checked = true;
                    char[] periods = che.period.ToCharArray();
                    foreach (char period in periods)
                    {
                        switch (period)
                        {
                            case '1':
                                period1.Checked = true;
                                break;
                            case '2':
                                period2.Checked = true;
                                break;
                            case '3':
                                period3.Checked = true;
                                break;
                            case '4':
                                period4.Checked = true;
                                break;
                            case '5':
                                period5.Checked = true;
                                break;
                            case '6':
                                period6.Checked = true;
                                break;
                            case '7':
                                period7.Checked = true;
                                break;
                        }
                    }

                }
                else
                {
                    this.ClientScript.RegisterStartupScript(GetType(), "msg", "<script>f_xuanhuan(1);</script>");
                    radxunhuan1.Checked = true;
                    radxunhuan2.Checked = false;
                }

                class_date.Value = Convert.ToDateTime(che.class_date).ToString("yyyy-MM-dd");
                starttime_hour.Value = Convert.ToDateTime(che.class_date).ToString("HH");
                starttime_minute.Value = Convert.ToDateTime(che.class_date).ToString("mm");

                Duration_hour.Value = Convert.ToInt32(Convert.ToInt32(che.Duration_date) / 60).ToString();
                Duration_minute.Value = Convert.ToInt32(Convert.ToInt32(che.Duration_date) % 60).ToString();

                before_time.Value = Convert.ToInt32(Convert.ToInt32(che.before_time) % 60).ToString();

                before_hour.Value = Convert.ToInt32(Convert.ToInt32(che.before_time) / 60).ToString();

                max_audio_chan.Value = che.max_audio_chan;
                max_video_chan.Value = che.max_video_chan;
                max_video_size.Value = che.max_video_size;

                def_video_size.Value = che.def_video_size;
                video_frame_rate.Value = che.video_frame_rate;
                max_bandwidth.Value = che.max_bandwidth;
                maliu.Value = che.maliu;

                if (che.mtg_mode == "1")
                {
                    mtg_mode1.Checked = true;
                    mtg_mode2.Checked = false;
                }
                else
                {
                    mtg_mode1.Checked = false;
                    mtg_mode2.Checked = true;
                }

                if (che.video_public == "1")
                {
                    video_public1.Checked = true;
                    video_public2.Checked = false;
                }
                else
                {
                    video_public1.Checked = false;
                    video_public2.Checked = true;
                }

                if (che.layout_mode == "0")
                {
                    layout_mode1.Checked = true;
                    layout_mode2.Checked = false;


                    video_layer.Style["Display"] = "Block"; //显示

                    video_layer1.Style["Display"] = "none"; //隐藏
                }
                else
                {
                    layout_mode1.Checked = false;
                    layout_mode2.Checked = true;

                    video_layer.Style["Display"] = "none"; //显示

                    video_layer1.Style["Display"] = "Block"; //隐藏
                }

                if (che.funSeting != null)
                {
                    if (che.funSeting.Contains("1"))
                        funSetingA.Checked = true;
                    else
                        funSetingA.Checked = false;

                    if (che.funSeting.Contains("2"))
                        funSetingB.Checked = true;
                    else
                        funSetingB.Checked = false;

                    if (che.funSeting.Contains("3"))
                        funSetingC.Checked = true;
                    else
                        funSetingC.Checked = false;

                    if (che.funSeting.Contains("4"))
                        funSetingD.Checked = true;
                    else
                        funSetingD.Checked = false;

                    if (che.funSeting.Contains("5"))
                        funSetingE.Checked = true;
                    else
                        funSetingE.Checked = false;
                }

                video_layer2.Checked = false;
                switch (che.video_layer)
                {
                    case "2":
                        video_layer2.Checked = true;
                        break;
                    case "4":
                        video_layer4.Checked = true;
                        break;
                    case "6":
                        video_layer6.Checked = true;
                        break;
                    case "8":
                        video_layer8.Checked = true;
                        break;
                    case "10":
                        video_layer10.Checked = true;
                        break;
                    case "11":
                        video_layer11.Checked = true;
                        break;
                    case "17":
                        video_layer17.Checked = true;
                        break;
                    case "20":
                        video_layer20.Checked = true;
                        break;


                    case "12":
                        video_layer12.Checked = true;
                        break;
                    case "13":
                        video_layer13.Checked = true;
                        break;
                    case "14":
                        video_layer14.Checked = true;
                        break;
                    case "18":
                        video_layer18.Checked = true;
                        break;
                    case "15":
                        video_layer15.Checked = true;
                        break;
                    case "19":
                        video_layer19.Checked = true;
                        break;
                    case "16":
                        video_layer16.Checked = true;
                        break;
                    case "21":
                        video_layer21.Checked = true;
                        break;
                    case "22":
                        video_layer22.Checked = true;
                        break;
                    case "23":
                        video_layer23.Checked = true;
                        break;
                    case "25":
                        video_layer25.Checked = true;
                        break;

                    case "24":
                        video_layer24.Checked = true;
                        break;
                    case "26":
                        video_layer26.Checked = true;
                        break;
                    case "27":
                        video_layer27.Checked = true;
                        break;
                    case "28":
                        video_layer28.Checked = true;
                        break;
                }
            }
        }

        protected void ddl_txtteachar_SelectedIndexChanged(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(ddl_txtteachar.SelectedValue);
            if (id > 0)
            {
                Traning_LecturerBLL tbll = new Traning_LecturerBLL();
                Traning_Lecturer model = tbll.GetModel(id);
                txtteachar.Value = model.lecturerName;
                lecturerImage.Value = model.lecturerImage;
                lecturerImages.ImageUrl = model.lecturerImage;
                txtreateachar.Value = model.lecturerDetail;
            }
            else
            {
                txtteachar.Value = "";
                lecturerImage.Value = "";
                txtreateachar.Value = "";
                lecturerImages.ImageUrl = "";
            }
        }

    }
}